package org.example.event;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

public class MyEventSource {

    @Getter
    private final String name;

    private final List<MyEventListener> listeners = new ArrayList<>();

    public MyEventSource(String name) {
        this.name = name;
    }

    public void addListener(MyEventListener listener) {
        listeners.add(listener);
    }

    public void notifyEvent(Object data) {
        for (MyEventListener listener : listeners) {
            listener.onEvent(new MyEvent(this, data));
        }
    }

    @Override
    public String toString() {
        return "MyEventSource{" +
                "name=" + name +
                '}';
    }
}
